<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Controller
 *
 * @author thuongnh
 */
class Controller {

    var $request;
    var $response;
    var $template;
    var $data;

    public function __construct($request, $response) {
        $this->request = $request;
        $this->response = $response;
        if (Config::getConfig("system", "module") == "1") {
            if (Config::getConfig("system", "layout") == "1") {
                $this->template = new Template("../app/$request->module/view/layout.html");
            } else {
                $this->template = new Template("../app/$request->module/view/" . strtolower($request->controller) . "/" . $request->action . ".html");
            }
        } else {
            if (Config::getConfig("system", "layout") == "1") {
                $this->template = new Template("../app/view/layout.html");
            } else {
                $this->template = new Template("../app/view/" . strtolower($request->controller) . "/" . $request->action . ".html");
            }
        }
        $this->data = $request->params;
    }

    protected function preDispatch() {
        
    }

    public function dispatch($action) {
        $this->preDispatch();
        if (array_keys(get_class_methods(get_class($this)), $action) != null) {
            $this->$action();
        }
        return $this->response;
    }

    protected function setLayout($layoutName) {
        if (Config::getConfig("system", "module") == "1") {
            $this->template = new Template("../app/$this->request->module/view/$layoutName.html");
        } else {
            $this->template = new Template("../app/view/$layoutName.html");
        }
    }

}

?>
